﻿Public Class cls_PrintTempUpdate
    Inherits cls_Database_Base
#Region "Get data"
    Public Function FuncG_GetData(ByVal iStr_ID As String) As DataTable
        Dim mvDataTale As New DataTable
        Dim mvStr_Sql As String = ""
        Try
            'Lấy ra máy in mà mặt hàng đang đặt với điều kiện : mặt hàng đó phải đc cho phép in
            ' và trạng thái của mặt hàng đó phải = 1 ( = 0 nghĩa là đã in xong rồi)
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT DISTINCT TBL_PRINTER.ID, TBL_PRINTER.NAME FROM TBL_PRINT_TEMP INNER JOIN"
                mvStr_Sql += "  TBL_ITEM ON TBL_PRINT_TEMP.LOC_ID = TBL_ITEM.LOC_ID AND TBL_PRINT_TEMP.ITEM_ID = TBL_ITEM.ID INNER JOIN"
                mvStr_Sql += "  TBL_PRINTER ON TBL_ITEM.LOC_ID = TBL_PRINTER.LOC_ID AND TBL_ITEM.PRINTER = TBL_PRINTER.ID"
                mvStr_Sql += "  WHERE TBL_PRINT_TEMP.LOC_ID = @iNVChr_LOCID AND TBL_PRINT_TEMP.INVOICE_ID = @iNVChr_ID AND TBL_ITEM.PRINTORDER = 1"
                mvStr_Sql += "  AND TBL_PRINT_TEMP.STATUS = 1"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iStr_ID)
                mvDataTale = FuncM_GetDataTable(mvStr_Sql)
            End If
        Catch ex As Exception
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return mvDataTale
    End Function
#End Region
#Region "Insert - Update"
    Public Function FuncG_InsertUpdate(ByVal iCls_PrintTemp As cls_PrintTemp) As Boolean
        Try
            If FuncM_OpenConnection() Then
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iCls_PrintTemp.ID)
                SubM_AddParameter("@iInt_ITEM", iCls_PrintTemp.ItemID)
                SubM_AddParameter("@iNVChr_EMPLOYEE", iCls_PrintTemp.Employee)
                SubM_AddParameter("@iFlt_QUANTITY", iCls_PrintTemp.Quantity)
                SubM_AddParameter("@iNVChr_DESCRIPTION", iCls_PrintTemp.Description)
                SubM_AddParameter("@iTInt_STATUS", iCls_PrintTemp.Status)
                If FuncM_ExecuteStore("usp_PrintTemp") Then
                    Return True
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Throw ex
            Return False
        Finally
            FuncM_CloseConnection()
        End Try
    End Function
    'Cập nhật lại trạng thái
    Public Function FuncG_Update(ByVal iStr_ID As String, ByVal iByte_Status As Byte) As Boolean
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "UPDATE TBL_PRINT_TEMP SET STATUS = @iTInt_STATUS WHERE LOC_ID = @iNVChr_LOCID AND INVOICE_ID = @iNVChr_ID"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iStr_ID)
                SubM_AddParameter("@iTInt_STATUS", iByte_Status)
                If FuncM_ExecuteNonQuery(mvStr_Sql) Then
                    Return True
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Throw ex
            Return False
        Finally
            FuncM_CloseConnection()
        End Try
    End Function
#End Region
#Region "Delete"
    Public Function FuncG_Delete(ByVal iStr_ID As String) As Boolean
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "DELETE TBL_PRINT_TEMP WHERE LOC_ID = @iNVChr_LOCID AND INVOICE_ID = @iNVChr_ID"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iStr_ID)
                If FuncM_ExecuteNonQuery(mvStr_Sql) Then
                    Return True
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Throw ex
            Return False
        Finally
            FuncM_CloseConnection()
        End Try
    End Function
    Public Function FuncG_DeleteItem(ByVal iCls_SalesDetail As cls_SalesDetail) As Boolean
        Try
            If FuncM_OpenConnection() Then
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iCls_SalesDetail.ID)
                SubM_AddParameter("@iInt_ITEM", iCls_SalesDetail.ItemID)
                SubM_AddParameter("@iFlt_RETURNQTY", iCls_SalesDetail.Quantity)
                If FuncM_ExecuteStore("usp_DeletePrintTemp") Then
                    Return True
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Throw ex
            Return False
        Finally
            FuncM_CloseConnection()
        End Try
    End Function
#End Region
End Class
